package com.eling.elcms.community.service.impl;

import com.eling.elcms.community.dao.IBuildingDao;
import com.eling.elcms.community.model.Building;
import com.eling.elcms.community.service.IBuildingManager;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import org.apache.commons.lang3.builder.CompareToBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class BuildingManagerImpl extends GenericManagerImpl<Building, Long> implements IBuildingManager {
	
    @Autowired
    public void setBuildingDao(IBuildingDao dao) {
        this.dao = dao;
    }
    
    
    public Set<Building> queryByPKs(Long[] pks){ 
		Set<Building> buildingSet = new HashSet<>(); 
		for (Long pkBuilding : pks) {
			buildingSet.add(this.get(pkBuilding));
		}
		return buildingSet;
    }
        
    @Override
    public List<Building> getAll() {
    	List<Building> list = super.getAll();
    	Collections.sort(list, (a,b)->new CompareToBuilder().append(a.getOrderCode(), b.getOrderCode()).build());
    	return list;
    }

}
